/**
 * col_action
 */
layui.define(['YunjColsTemplet','dropdown'], function (exports) {

    let YunjColsTemplet = layui.YunjColsTemplet;
    let dropdown = layui.dropdown;

    class YunjColsTempletAction extends YunjColsTemplet{

        constructor(options) {
            super(options);
        }

        layout(){
            let that=this;
            let options=that.args.options;
            if(options.length<=0) return '';

            let templet='';
            if(yunj.isMobile()){
                for(let i=0,l=options.length;i<l;i++){
                    let option=options[i];
                    let c=`${option.icon?option.icon:''} ${option.class?option.class:''}`;
                    let a=JSON.stringify(option);
                    templet+=`<dd class="${c}" lay-event="${option.type}" data-args='${a}'>${option.title}</dd>`;
                }
                templet=dropdown.layout(templet);
            }else {
                let itemTemplet='';
                let dropdownTemplet='';
                for(let i=0,l=options.length;i<l;i++){
                    let option=options[i];
                    let c=`${option.icon?option.icon:''} ${option.class?option.class:''}`;
                    let a=JSON.stringify(option);
                    option.dropdown?dropdownTemplet+=`<dd class="${c}" lay-event="${option.type}" data-args='${a}'>${option.title}</dd>`:itemTemplet+=`<button type="button" class="layui-btn layui-btn-xs layui-btn-primary ${c}" lay-event="${option.type}" data-args='${a}'>${option.title}</button>`;
                }
                if(itemTemplet) templet+=`<div class="layui-btn-group" style="margin-right: 10px">${itemTemplet}</div>`;
                if(dropdownTemplet) templet+=dropdown.layout(dropdownTemplet);
            }
            return `<div class="layui-btn-container" yunj-id="${that.tableId}">${templet}</div>`;
        }

    }

    exports('col_action', YunjColsTempletAction);
});